package com.drinks.yiniang.ui.activity.goods;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.TabLayout;
import android.os.Bundle;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearSmoothScroller;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.StyleSpan;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.banner.GoodsBannerRecyclerAdapter;
import com.drinks.yiniang.adapter.goods.GoodsDetailAdapter;
import com.drinks.yiniang.common.recycler.decoration.GoodsDetailItemDecoration;
import com.drinks.yiniang.common.listener.OnGoodsNavigationBarClickListener;
import com.drinks.yiniang.common.recycler.scroller.ItemSmoothScroller;
import com.drinks.yiniang.entity.comment.GoodsCommentJson;
import com.drinks.yiniang.entity.common.StringJson;
import com.drinks.yiniang.entity.goods.GoodsDetailJson;
import com.drinks.yiniang.entity.goods.GoodsJson;
import com.drinks.yiniang.entity.goods.GoodsObject;
import com.drinks.yiniang.entity.goods.RecommendGoodsJson;
import com.drinks.yiniang.io.api.GoodsApiIO;
import com.drinks.yiniang.io.api.ShoppingCartApiIO;
import com.drinks.yiniang.ui.activity.shop.ShopListActivity;
import com.drinks.yiniang.ui.widget.dialog.AddToCartDialog;
import com.drinks.yiniang.ui.widget.dialog.WineListDialog;
import com.drinks.yiniang.ui.widget.layout.GoodsDetailBottomLayout;
import com.drinks.yiniang.ui.widget.nav.NavigationGoodsDetailLayout;
import com.drinks.yiniang.ui.widget.recycler.BaseRecyclerView;
import com.drinks.yiniang.utils.ActivityUtils;
import com.drinks.yiniang.utils.GlideUtils;
import com.drinks.yiniang.utils.RecyclerUtils;
import com.drinks.yiniang.utils.ToastUtils;
import com.hansen.library.Constants;
import com.hansen.library.entity.BaseJson;
import com.hansen.library.io.tuple.Tuple2;
import com.hansen.library.listener.APIRequestCallback;
import com.hansen.library.ui.activity.BaseTranBarActivity;
import com.hansen.library.ui.widget.banner.BannerConfig;
import com.hansen.library.ui.widget.banner.recycler.RecyclerBannerLayout;
import com.hansen.library.ui.widget.layout.AutoLineFeedLayout;
import com.hansen.library.utils.ColorUtils;
import com.hansen.library.utils.CommonUtils;
import com.hansen.library.utils.ScreenSizeUtils;
import com.hansen.library.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

import static com.drinks.yiniang.entity.goods.GoodsDetailJson.ITEM_TYPE_GOODS_COMMENT;
import static com.drinks.yiniang.entity.goods.GoodsDetailJson.ITEM_TYPE_GOODS_RECOMMENT_LIST;
import static com.drinks.yiniang.entity.goods.GoodsDetailJson.ITEM_TYPE_GOODS_RECOMMENT_TITLE;
import static com.drinks.yiniang.entity.goods.GoodsDetailJson.ITEM_TYPE_GOODS_WEB;

/**
 * 商品详情页面
 *
 * @author han
 * Created by han on 2019/11/06
 */
public class GoodsDetailsActivity extends BaseTranBarActivity implements AppBarLayout.OnOffsetChangedListener,
        OnGoodsNavigationBarClickListener, TabLayout.OnTabSelectedListener, GoodsDetailBottomLayout.OnGoodsBuyClickListener,
        BaseQuickAdapter.OnItemClickListener, BaseQuickAdapter.OnItemChildClickListener, AddToCartDialog.OnAddToCartClickListener {

    //nav
    private NavigationGoodsDetailLayout nav_goods_detail;
    private AppBarLayout app_bar_goods_detail;
    //banner
    private RecyclerBannerLayout banner_goods_detail;
    private BaseRecyclerView rcv_goods_detail;
    private GoodsDetailBottomLayout ll_goods_detail_bottom;
    //header view
    //商品价格
    private TextView tv_goods_detail_price;
    //分享按钮
    private TextView tv_goods_detail_share;
    //商品名
    private TextView tv_goods_detail_name;
    //推荐语
    private TextView tv_goods_detail_slogan;
    //选择规格
    private TextView tv_goods_detail_attrs_value;
    //送达时间
    private TextView tv_goods_detail_service_time_value;
    //标签容器
    private AutoLineFeedLayout auto_goods_detail_label;
    //广告banner
    private ImageView iv_goods_detail_ad;

    private GoodsDetailAdapter mGoodsDetailAdapter;
    private GoodsBannerRecyclerAdapter mBannerAdapter;

    private LinearSmoothScroller mSmoothScroller;

    private GridLayoutManager mGridLayoutManager;

    private int mAppBarTotalScrollRange;
    private int dp10, dp40;

    //商品id
    private String mGoodsId;
    //用于页面传参的object
    private GoodsObject mGoodsObject;
    //banner
    private String mBannerType;
    private String mBannerValue;

    @Override
    protected void initView() {
        nav_goods_detail = findViewById(R.id.nav_goods_detail);

        app_bar_goods_detail = findViewById(R.id.app_bar_goods_detail);

        banner_goods_detail = findViewById(R.id.banner_goods_detail);

        rcv_goods_detail = findViewById(R.id.rcv_goods_detail);

        ll_goods_detail_bottom = findViewById(R.id.ll_goods_detail_bottom);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        mContext = this;

        app_bar_goods_detail.post(new Runnable() {
            @Override
            public void run() {
                mAppBarTotalScrollRange = app_bar_goods_detail.getTotalScrollRange();
            }
        });

        if (getIntent() != null) {
            mGoodsId = getIntent().getStringExtra(Constants.KeyGoodsId);
        }

        initBanner();
        initAdapter();
        getGoodsDetail();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
//        setIntent(intent);
//
//        if (getIntent() != null) {
//            mGoodsId = getIntent().getStringExtra(Constants.KeyGoodsId);
//        }
//
//        app_bar_goods_detail.setExpanded(true, false);
//        mSmoothScroller.setTargetPosition(0);
//        mGridLayoutManager.startSmoothScroll(mSmoothScroller);
//
//        setGoodsData(null);
//        setGoodsCollectData(Constants.STATUS_GLOBAL_NO);
//        getGoodsDetail();
    }

    private void initAdapter() {
        mGoodsDetailAdapter = new GoodsDetailAdapter(mContext, new ArrayList<GoodsDetailJson.GoodsDetailList>());
        mGoodsDetailAdapter.addHeaderView(getHeaderView());
        mGoodsDetailAdapter.setHeaderAndEmpty(true);
        mGoodsDetailAdapter.setCommonEmpty(getLayoutInflater(), rcv_goods_detail);
        mGoodsDetailAdapter.bindToRecyclerView(rcv_goods_detail);

        mGridLayoutManager = RecyclerUtils.getGoodsDetailGridLayout(mContext, mGoodsDetailAdapter.getData());

        rcv_goods_detail.setLayoutManager(mGridLayoutManager);
        rcv_goods_detail.addItemDecoration(GoodsDetailItemDecoration.getItemDPDecoration(10));

        mSmoothScroller = new ItemSmoothScroller(mContext);
    }

    //获取header
    private View getHeaderView() {
        View mHeaderView = getLayoutInflater().inflate(R.layout.header_goods_detail, (ViewGroup) rcv_goods_detail.getParent(), false);

        tv_goods_detail_price = mHeaderView.findViewById(R.id.tv_goods_detail_price);
        tv_goods_detail_share = mHeaderView.findViewById(R.id.tv_goods_detail_share);
        tv_goods_detail_name = mHeaderView.findViewById(R.id.tv_goods_detail_name);
        tv_goods_detail_slogan = mHeaderView.findViewById(R.id.tv_goods_detail_slogan);
        tv_goods_detail_attrs_value = mHeaderView.findViewById(R.id.tv_goods_detail_attrs_value);
        tv_goods_detail_service_time_value = mHeaderView.findViewById(R.id.tv_goods_detail_service_time_value);

        auto_goods_detail_label = mHeaderView.findViewById(R.id.auto_goods_detail_label);

        iv_goods_detail_ad = mHeaderView.findViewById(R.id.iv_goods_detail_ad);

        iv_goods_detail_ad.setOnClickListener(this);
        tv_goods_detail_share.setOnClickListener(this);
        tv_goods_detail_attrs_value.setOnClickListener(this);

        return mHeaderView;
    }

    private void initBanner() {
        mBannerAdapter = new GoodsBannerRecyclerAdapter(mContext);

        banner_goods_detail.setAutoPlay(false)
                .setLoop(false)
                .setBannerStyle(BannerConfig.NUM_INDICATOR)
                .setBannerAdapter(mBannerAdapter)
                .start();
    }

    @Override
    protected void initListener() {
        app_bar_goods_detail.addOnOffsetChangedListener(this);
        nav_goods_detail.setOnNavgationBarClickListener(this);
        nav_goods_detail.setOnTabSelectedListener(this);
        ll_goods_detail_bottom.setOnCartBuyClickListener(this);
        mGoodsDetailAdapter.setOnItemClickListener(this);
        mGoodsDetailAdapter.setOnItemChildClickListener(this);
        addRecyclerOnScrollListener();
    }

    @Override
    public void widgetClick(View v) {
        switch (v.getId()) {
            case R.id.tv_goods_detail_share://分享

                break;
            case R.id.tv_goods_detail_attrs_value://选择规格
                if(!ActivityUtils.isLogined(this, true)) {
                    return;
                }
                if(ll_goods_detail_bottom.isAddToCartEnable()) initAddDialog(AddToCartDialog.TYPE_ADD_TO_CART_DEFAULT);
                break;
            case R.id.iv_goods_detail_ad://banner
                ActivityUtils.startActivityByAdType(mContext, mBannerType, mBannerValue);
                break;
            default:
                break;
        }
    }

    @Override
    public int getTranBarResID() {
        return R.layout.activity_goods_details;
    }

    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        if (mAppBarTotalScrollRange > 0) {
            float fraction = Math.abs(verticalOffset * 1.0f) / mAppBarTotalScrollRange;
            nav_goods_detail.setBackgroundColor(ColorUtils.changeAlpha(Color.WHITE, fraction));
            //nav_goods_detail.setAlpha(fraction);

            nav_goods_detail.setTabLayoutAlpha(fraction);
        }
    }

    @Override
    public void onBackClick(View v) {
        finish();
    }

    @Override
    public void onShareClick(View v) {//分享

    }

    @Override
    public void onCartClick(View v) {//进入购物车
        //购物车
        Intent intent = new Intent(mContext, ShoppingCartActivity.class);
        startActivity(intent);
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        if (tab.getPosition() == 0) {
            app_bar_goods_detail.setExpanded(true, false);
        } else {
            app_bar_goods_detail.setExpanded(false, false);
        }
        mSmoothScroller.setTargetPosition(tab.getPosition());
        mGridLayoutManager.startSmoothScroll(mSmoothScroller);
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }

    @Override
    public void onBuyClick(View v) {//立即购买
        if(!ActivityUtils.isLogined(this, true)) {
            return;
        }
        initAddDialog(AddToCartDialog.TYPE_ADD_TO_CART_BUY);
    }

    @Override
    public void onAddToCartClick(View v) {//加入购物车
        if(!ActivityUtils.isLogined(this, true)) {
            return;
        }
        initAddDialog(AddToCartDialog.TYPE_ADD_TO_CART_ADD);
    }

    @Override
    public void onShopClick(View v) {//门店
        Intent intent = new Intent(mContext, ShopListActivity.class);
        startActivity(intent);
    }

    @Override
    public void onWishListClick(View v) {//收藏到心愿清单
        if(!ActivityUtils.isLogined(this, true)) {
            return;
        }
        doGoodsCollectOrCancel();
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
        Intent mIntent;

        GoodsDetailJson.GoodsDetailList data = mGoodsDetailAdapter.getItem(position);

        if(data == null) {
            return;
        }

        switch (adapter.getItemViewType(position + adapter.getHeaderLayoutCount())) {
            case ITEM_TYPE_GOODS_RECOMMENT_LIST://推荐商品
                mIntent = new Intent(mContext, GoodsDetailsActivity.class);
                mIntent.putExtra(Constants.KeyGoodsId, data.getId());
                startActivity(mIntent);
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
        Intent mIntent;

        switch (adapter.getItemViewType(position + adapter.getHeaderLayoutCount())) {
            case ITEM_TYPE_GOODS_COMMENT://评论item type
                if (view.getId() == R.id.tv_goods_detail_comment_all) {//全部评论
                    mIntent = new Intent(mContext, GoodsCommentsActivity.class);
                    mIntent.putExtra(Constants.KeyGoodsId, mGoodsId);
                    startActivity(mIntent);
                } else if(view.getId() == R.id.tv_gd_all_expert_comment) {
                    mIntent = new Intent(mContext, GoodsCommentsActivity.class);
                    mIntent.putExtra(Constants.KeyGoodsId, mGoodsId);
                    mIntent.putExtra(Constants.KeyType, Constants.TYPE_GOODS_COMMENTS_SPECIALIST);
                    startActivity(mIntent);
                }
            case ITEM_TYPE_GOODS_WEB:
                if (view.getId() == R.id.btn_goods_detail_join) {//加入酒单
                    initWineListDialog();
                }
                break;
            case ITEM_TYPE_GOODS_RECOMMENT_LIST://推荐商品
                GoodsJson.GoodsList data = mGoodsDetailAdapter.getItem(position);

                if(data != null && view.getId() == R.id.iv_home_goods_add_cart) {
                    addToCart(data.getId());
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void onAddToCartAddClick(String attrs, int count) {

    }

    @Override
    public void onAddToCartBuyClick(String attrs, int count) {

    }

    private void initAddDialog(@AddToCartDialog.AddToCartDialogTypeDef int type) {
        AddToCartDialog addToCartDialog = AddToCartDialog.newInstance(mGoodsObject, type);

        addToCartDialog.show(getSupportFragmentManager(), Constants.TAG_ADD_TO_CART_DIALOG);
    }

    private void initWineListDialog() {
        WineListDialog wineListDialog = WineListDialog.newInstance(mGoodsObject);

        wineListDialog.show(getSupportFragmentManager(), Constants.TAG_WINE_LIST_DIALOG);
    }

    //收藏或取消收藏
    private void doGoodsCollectOrCancel() {
        if (StringUtils.isEmpty(mGoodsId)) {
            ToastUtils.showShort(getString(R.string.text_the_goods_does_not_exist));
            return;
        }

        showLoadingDialog();

        GoodsApiIO.getInstance().doGoodsCollectOrCancel(mGoodsId, new APIRequestCallback<StringJson, Tuple2<Integer, String>>() {
            @Override
            public void onSuccess(StringJson res) {
                ll_goods_detail_bottom.setWishTextStatus(!ll_goods_detail_bottom.isCollectGoods());
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                ToastUtils.showShort(error._2);
            }

            @Override
            public void onComplete() {
                dismissDialog();
            }
        });
    }

    private void addToCart(String goodsId) {
        //设置传参object
        showLoadingDialog();

        ShoppingCartApiIO.getInstance().addToShopCart(goodsId, new APIRequestCallback<BaseJson, Tuple2<Integer, String>>() {
            @Override
            public void onSuccess(BaseJson res) {
                ToastUtils.showShort(getString(R.string.text_add_success));
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                ToastUtils.showShort(error._2);
            }

            @Override
            public void onComplete() {
                dismissDialog();
            }
        });
    }

    //获取推荐列表
    private void getRecommend() {
        GoodsApiIO.getInstance().getRecommendGoodsList(new APIRequestCallback<RecommendGoodsJson, Tuple2<Integer, String>>() {
            @Override
            public void onSuccess(RecommendGoodsJson res) {
                if (mGoodsDetailAdapter == null) {
                    return;
                }

                List<GoodsDetailJson.GoodsDetailList> ls = new ArrayList<>();
                GoodsDetailJson.GoodsDetailList data;
                GoodsJson.GoodsList goodsData;

                for (int i = 0; i < res.getData().size(); i++) {
                    goodsData = res.getData().get(i);
                    data = new GoodsDetailJson.GoodsDetailList();

                    data.setItemType(ITEM_TYPE_GOODS_RECOMMENT_LIST);
                    data.setId(goodsData.getId());
                    data.setCover_url(goodsData.getCover_url());
                    data.setName(goodsData.getName());
                    data.setEn_name(goodsData.getEn_name());
                    data.setApp_price(goodsData.getApp_price());
                    data.setActivity(goodsData.getActivity());
                    data.setIs_show_contrast(goodsData.getIs_show_contrast());
                    data.setRecommend_reason(goodsData.getRecommend_reason());

                    ls.add(data);
                }

                mGoodsDetailAdapter.addData(ls);
                mGoodsDetailAdapter.loadMoreEnd();
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                mGoodsDetailAdapter.loadMoreFail();
            }

            @Override
            public void onComplete() {
            }
        });
    }

    //获取商品详情
    private void getGoodsDetail() {
        if (StringUtils.isEmpty(mGoodsId)) {
            ToastUtils.showShort(getString(R.string.text_the_goods_does_not_exist));
            return;
        }

        showLoadingDialog();

        GoodsApiIO.getInstance().getGoodsDetail(mGoodsId, new APIRequestCallback<GoodsDetailJson, Tuple2<Integer, String>>() {
            @Override
            public void onSuccess(GoodsDetailJson res) {
                if (mGoodsDetailAdapter == null) {
                    return;
                }

                mGoodsDetailAdapter.getData().clear();

                setGoodsData(res.getData());

                List<GoodsDetailJson.GoodsDetailList> ls = new ArrayList<>();

                //评论
                GoodsDetailJson.GoodsDetailList data = new GoodsDetailJson.GoodsDetailList();
                data.setItemType(ITEM_TYPE_GOODS_COMMENT);
                data.setTempCommentCount(res.getData().getComment_count());

                data.setTempComment(res.getData().getComment());
                data.setTempParams(res.getData().getParams());
                ls.add(data);
                //web
                data = new GoodsDetailJson.GoodsDetailList();
                data.setItemType(ITEM_TYPE_GOODS_WEB);
                data.setTempGoodsContent(res.getData().getDescription());
                ls.add(data);
                //推荐标题
                data = new GoodsDetailJson.GoodsDetailList();
                data.setItemType(ITEM_TYPE_GOODS_RECOMMENT_TITLE);
                ls.add(data);

                mGoodsDetailAdapter.addData(ls);

                //预售
                ll_goods_detail_bottom.setAddToCartBtnVisibilityGone(!Constants.STATUS_GLOBAL_YES.equals(res.getData().getIs_forword_sale()));
                ll_goods_detail_bottom.setButtonEnable(true, !Constants.STATUS_GLOBAL_YES.equals(res.getData().getIs_forword_sale()));

                //推荐商品
                getRecommend();
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                ToastUtils.showShort(error._2);
                mGoodsDetailAdapter.loadMoreFail();
            }

            @Override
            public void onComplete() {
                dismissDialog();
            }
        });
    }

    //设置商品数据
    private void setGoodsData(GoodsDetailJson.GoodsDetailData data) {
        if(data == null) {
            data = new GoodsDetailJson.GoodsDetailData();
        }

        int sp13 = ScreenSizeUtils.sp2Px(mContext, 13);

        dp10 = ScreenSizeUtils.dp2px(mContext, 10);
        dp40 = ScreenSizeUtils.dp2px(mContext, 40);

        mBannerAdapter.addBannerData(data.getGoods_images());
        banner_goods_detail.update();

        //价格
        SpannableStringBuilder builder = new SpannableStringBuilder("¥");
        int start = builder.length();
        builder.append(StringUtils.getNullEmptyConvert__(data.getApp_price()));
        int end = builder.length();
        builder.append("/");
        builder.append(StringUtils.getNullEmptyConvert__(data.getPack_method()));
        builder.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        builder.setSpan(new AbsoluteSizeSpan(sp13), end, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv_goods_detail_price.setText(builder);
        //名称
        tv_goods_detail_name.setText(data.getName());
        //推荐语
        tv_goods_detail_slogan.setText(data.getRecommend_reason());
        //标签
        auto_goods_detail_label.removeAllViews();

        if (!CommonUtils.isEmptyList(data.getGoods_label())) {
            for (int i = 0; i < data.getGoods_label().size(); i++) {
                auto_goods_detail_label.addView(getLabelChild(data.getGoods_label().get(i)));
            }
        }

        //ad banner
        if(data.getBanner() != null) {
            iv_goods_detail_ad.setVisibility(View.VISIBLE);
            GlideUtils.loadBannerImage(mContext, iv_goods_detail_ad, data.getBanner().getCover_url());

            mBannerType = data.getBanner().getType();
            mBannerValue = data.getBanner().getValue();
        } else {
            iv_goods_detail_ad.setVisibility(View.GONE);
        }

        //设置传参object
        if (mGoodsObject == null) {
            mGoodsObject = new GoodsObject();
        }
        mGoodsObject.setId(data.getId());
        mGoodsObject.setApp_price(data.getApp_price());
        mGoodsObject.setName(data.getName());
        mGoodsObject.setSub_title(data.getSub_title());
        mGoodsObject.setSku(data.getSku());

        if (!CommonUtils.isEmptyList(data.getGoods_images())) {
            mGoodsObject.setCoverUrl(data.getGoods_images().get(0));
        }

        //设置是否收藏
        setGoodsCollectData(data.getIs_collect());
    }

    private void setGoodsCollectData(String collectStatus) {
        ll_goods_detail_bottom.setWishTextStatus(Constants.STATUS_GLOBAL_YES.equals(collectStatus));
    }

    private AppCompatTextView getLabelChild(String label) {
        AppCompatTextView tv = new AppCompatTextView(mContext);


        tv.setMinWidth(dp40);
        tv.setText(label);
        tv.setPadding(dp10, 10, dp10, 10);
        tv.setGravity(Gravity.CENTER_HORIZONTAL);
        tv.setTextColor(ColorUtils.getColorById(mContext, com.hansen.library.R.color.color_ceb689));
        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
        tv.setBackgroundResource(R.drawable.shape_label_border);

        return tv;
    }

    private void addRecyclerOnScrollListener() {
        rcv_goods_detail.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                //当前屏幕 首个 可见的 Item 的position
                int firstVisibleItem = mGridLayoutManager.findFirstVisibleItemPosition();

                switch (firstVisibleItem) {
                    case 3://推荐
                        nav_goods_detail.setTabLayoutSelected(3);
                        break;
                    case 2://详情
                        nav_goods_detail.setTabLayoutSelected(2);
                        break;
                    case 1://评价
                        nav_goods_detail.setTabLayoutSelected(1);
                        break;
                    case 0://商品
                        nav_goods_detail.setTabLayoutSelected(0);
                        break;
                        default:
                            break;
                }
            }
        });
    }

    @Override
    protected void onDestroy() {
        if(mGoodsDetailAdapter != null) {
            mGoodsDetailAdapter.destroyWebview();
        }
        super.onDestroy();
    }
}
